// Layout组件
import Layout from '@/components/Layout.vue';
let route_tree = (state, getters) => {
    // 筛选一级路由
    let route_1st = state.routes.filter((route) => route.parent_id === 0)
    let parseToTree = (origin,list) => {
        return list.map((parent) => {
            let { route_path, route_name, require_auth, route_title,component_path } = parent;
            // 尝试筛选子集路由
            let children = origin.filter((route) => route.parent_id === parent.route_id);
            // 基础路由对象
            let route = {
                path: route_path,
                name: route_name,
                component: '',
                meta: { require_auth, route_title },
            }
            if (children.length > 0) {
                route.component = Layout;
                route.children=parseToTree(origin,children);
            } else {
                route.component=()=>import(`@/views${component_path}`);
            }
            return route;
        });
    }
    return parseToTree(state.routes,route_1st);
}

let has_operation=(state, getters)=>{
    return (code)=>{
        return state.operations.some((item)=>item.permission_code===code);
    }
}
export default {
    route_tree,
    has_operation
}